package com.example.pachong.service.impl;

import com.example.pachong.mapper.UserMapper;
import com.example.pachong.pojo.Users;
import com.example.pachong.service.UserService;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;


    @Override
    public void tianjia(Users user) {
        Users users = userMapper.selectByUid(user.getUid());
        if(users != null){
            if(!users.getNickname().equals(user.getNickname())){
                user.setTemp(users.getTemp()+1);
            }
            int newt = Integer.parseInt(user.getFinallytime());
            int oldt = Integer.parseInt(users.getFinallytime());
            if(newt < oldt){
                int temp = newt;
                newt = oldt;
                oldt = temp;
                user.setFinallytime(String.valueOf(newt));
            }
            if((newt-oldt)<10) {
                user.setShorttemp(users.getShorttemp() + 1);
            }
            user.setFreq(users.getFreq()+1);
            userMapper.updateUser(user);
        }else{
            user.setFreq(1);
            user.setTemp(0);
            user.setShorttemp(0);
            userMapper.insertUser(user);
        }
    }
}
